/// @tags: SplaywithReverseTag
#include <algorithm>
#include <cctype>
#include <cstdio>

namespace BlueQuantum {

int const N = 1e5 + 5;

template <typename T>
inline T &read(T &x) {
  x = 0;
  bool f = false;
  short ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = true;
    ch = getchar();
  }
  while (isdigit(ch)) x = x * 10 + (ch ^ '0'), ch = getchar();
  if (f) x = -x;
  return x;
}

struct Node {
  int ch[2], fa, val, siz;
  bool rev;
} tr[N];

int n, m, rt, tot;

inline bool iden(int x) { return tr[tr[x].fa].ch[1] == x; }

inline void pushup(int x) { tr[x].siz = 1 + tr[tr[x].ch[0]].siz + tr[tr[x].ch[1]].siz; }

inline void rotate(int x) {
  bool xtofa = iden(x);
  int fa = tr[x].fa, ffa = tr[fa].fa, ch = tr[x].ch[!xtofa];
  if (ffa) tr[ffa].ch[iden(fa)] = x;
  tr[fa].fa = x;
  tr[x].ch[!xtofa] = fa;
  tr[x].fa = ffa;
  tr[fa].ch[xtofa] = ch;
  if (ch) tr[ch].fa = fa;
  pushup(fa), pushup(x);
}

inline void reverse(int x) { tr[x].rev ^= 1; }

inline void pushdown(int x) {
  if (tr[x].rev) {
    std::swap(tr[x].ch[0], tr[x].ch[1]);
    if (tr[x].ch[0]) reverse(tr[x].ch[0]);
    if (tr[x].ch[1]) reverse(tr[x].ch[1]);
    tr[x].rev = false;
  }
}

inline void splay(int x, int tar = 0) {
  for (int fa; (fa = tr[x].fa); rotate(x))
    if (tr[fa].fa) rotate(iden(fa) == iden(x) ? fa : x);
  pushup(x);
  if (!tar) rt = x;
}

inline int build(int l, int r) {
  if (l > r) return 0;
  int mid = (l + r) >> 1;
  tr[mid].ch[0] = build(l, mid - 1), tr[mid].ch[1] = build(mid + 1, r);
  if (tr[mid].ch[0]) tr[tr[mid].ch[0]].fa = mid;
  if (tr[mid].ch[1]) tr[tr[mid].ch[1]].fa = mid;
  pushup(mid);
  return mid;
}

inline int find(int x) {
  int cur = rt;
  while (true) {
    pushdown(cur);
    if (x <= tr[tr[cur].ch[0]].siz) cur = tr[cur].ch[0];
    else if (x == tr[tr[cur].ch[0]].siz + 1) {
      break;
    } else {
      x -= tr[tr[cur].ch[0]].siz + 1;
      cur = tr[cur].ch[1];
    }
  }
  splay(cur);
  return cur;
}

inline int split(int k) {
  if (k < tr[rt].siz) {
    int cur = find(k + 1);
    tr[cur].siz -= tr[tr[cur].ch[0]].siz;
    int tmp = tr[cur].ch[0];
    tr[cur].ch[0] = 0;
    tr[tmp].fa = 0;
    return tmp;
  } else {
    int cur = rt;
    rt = 0;
    return cur;
  }
}

inline void merge(int a) {
  if (!rt) return rt = a, void();
  find(1);
  tr[rt].siz += tr[a].siz;
  tr[rt].ch[0] = a;
  tr[a].fa = rt;
}

inline void print(int x) {
  if (!x) return;
  pushdown(x);
  print(tr[x].ch[0]);
  printf("%d ", x);
  print(tr[x].ch[1]);
}

inline int main() {
  read(n), read(m);
  rt = build(1, n);
  for (int i = 1, A, B, C; i <= m; ++i) {
    read(A), read(B), read(C);
    int a = split(A);
    int b = split(B);
    merge(a);
    tr[b].rev ^= 1;
    int c = split(C);
    merge(b);
    merge(c);
  }
  print(rt);
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("旅行.in", "r", stdin);
  freopen("旅行.out", "w", stdout);
#endif
#endif

  return BlueQuantum::main();
}